package com.cloudeasy.area.client;


import com.cloudeasy.api.enums.ResultCodeEnum;
import com.cloudeasy.api.util.ResultUtil;
import com.cloudeasy.api.vo.Result;
import com.cloudeasy.api.vo.oauth.JWT;
import com.cloudeasy.api.vo.oauth.OAuthUserEnableRolesVO;
import com.cloudeasy.api.vo.user.PermissionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@FeignClient(value = "cloudeasy-server", fallback = ServerClient.ServerClientFallback.class)
public interface ServerClient {
    /**
     * 获取用户可用角色
     *
     * @param account 账号
     * @return {@link OAuthUserEnableRolesVO}的{@link Result}
     */
    @GetMapping("/oauth/{account}/role")
    Result<OAuthUserEnableRolesVO> getUserEnableRole(@PathVariable("account") String account);

    /**
     * 获取用户可用权限
     *
     * @param account 账号
     * @return {@link List<PermissionVO>}的{@link Result}
     */
    @GetMapping("/oauth/{account}/permission")
    Result<List<PermissionVO>> getUserEnablePermission(@PathVariable("account") String account);

    @Slf4j
    @Component
    static class ServerClientFallback implements ServerClient {
        @Override
        public Result<OAuthUserEnableRolesVO> getUserEnableRole(String account) {
            return ResultUtil.failure(ResultCodeEnum.REMOTE_ERROR);
        }

        @Override
        public Result<List<PermissionVO>> getUserEnablePermission(String account) {
            return ResultUtil.failure(ResultCodeEnum.REMOTE_ERROR);
        }
    }
}
